package written.w20241224flygyy.Q2;

/**
 * MAin
 *
 * @Author : Ruoyu Wang
 * @DateTime : 2024/12/24 20:14
 */
public class Main {
    static char[] tmp;

    public static void main(String[] args) {
        String s = "yujwedjhccdskdsewirewrwsadm,fnsdklwweqpq";
        System.out.println(s);
        char[] chs = new char[s.length()];
        int n = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != 'w') {
                chs[n++] = s.charAt(i);
            }
        }
        tmp = new char[n];
        mergeSort(chs, 0, n - 1);
        for (int i = 0; i < n; i++) {
            System.out.print(chs[i]);
        }
        System.out.println();
    }

    public static void mergeSort(char[] chs, int l, int r) {
        if (l >= r) return;
        int x = (l + r) >> 1;
        mergeSort(chs, l, x);
        mergeSort(chs, x + 1, r);

        int k = 0;
        int a = l;
        int b = x + 1;
        while (a <= x && b <= r) {
            if (chs[a] < chs[b]) {
                tmp[k++] = chs[a++];
            } else {
                tmp[k++] = chs[b++];
            }
        }
        while (a <= x) {
            tmp[k++] = chs[a++];
        }
        while (b <= r) {
            tmp[k++] = chs[b++];
        }
        for (int i = 0, j = l; i < k; i++, j++) {
            chs[j] = tmp[i];
        }
    }
}
